package main

import (
	"fmt"
	"time"
)

type service struct {
	name string
}

func (a *service) callback(r *result) {

	fmt.Println(fmt.Sprintf("%v,%p %x %v %+v", a, a, a, a.name, r))
}

func (a *service) run() {

	var (
		fCallBack = func(r *result) {
			a.callback(r)
		}
		rr = newResult(fCallBack, a.name)
	)

	rr.run()
}

type result struct {
	name      string
	fCallBack func(*result)
}

func newResult(f func(*result), name string) *result {
	return &result{
		name:      name,
		fCallBack: f,
	}
}

func (r *result) run() {

	for i := 0; i < 3; i++ {
		go func() {
			for j := 0; j < 5; j++ {
				time.Sleep(time.Second)
				r.fCallBack(r)
			}
		}()
	}
}

func main() {

	index := 1
	for {
		srv := &service{
			name: fmt.Sprintf("%v%v", "zhangsan", index),
		}
		index = index + 1
		srv.run()
		time.Sleep(time.Second * 10)
	}
}
